package com.it.gmall.all.controller;

import com.it.gmall.activity.client.ActivityFeignClient;
import com.it.gmall.model.activity.SeckillGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class SeckillController {
    @Autowired
    private ActivityFeignClient activityFeignClient;

    // 首页数据显示
    @GetMapping("activity.html")
    public String seckillIndexGoods(Model model){
        List<SeckillGoods> indexGoods = activityFeignClient.getIndexGoods();
        model.addAttribute("list",indexGoods);
        return "seckill/index";
    }

    // 获取秒杀商品详情
    @GetMapping("/seckill/{skuId}.html")
    public String item(@PathVariable Long skuId, Model model){
        SeckillGoods seckillGoods = activityFeignClient.item(skuId);
        model.addAttribute("item",seckillGoods);
        return "seckill/item";
    }

    @GetMapping("seckill/queue.html")
    public String queue(@RequestParam(name = "skuId") Long skuId,
                        @RequestParam(name = "skuIdStr") String skuIdStr,
                        HttpServletRequest request){
        request.setAttribute("skuId", skuId);
        request.setAttribute("skuIdStr", skuIdStr);
        return "seckill/queue";
    }
}
